<?php if (!isset($_SESSION)) session_start(); ?>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="../../docs-assets/ico/favicon.png">

<title>Koreanet</title>

<!-- Nanum Webfont -->
<style>
* {
	font-family: 'NanumGothic' !important;
}
</style>
<script src="http://www.google.com/jsapi"></script>
<script>
 google.load( "webfont", "1" );
 google.setOnLoadCallback(function() {
  WebFont.load({ custom: {
   families: [ "NanumGothic" ],
   urls: [ "http://fontface.kr/NanumGothic/css" ]
  }});
 });
</script>

<!-- Bootstrap core CSS -->
<link href="./dist/css/bootstrap.css" rel="stylesheet">

<!-- Custom styles for this template -->
<link href="./css/vehicle_detail.css" rel="stylesheet">

</head>

<body>
<?php include 'header.php';?>
<?php require_once './class/Vehicle.inc';?>
<?php require_once './class/Category.inc';?>

	<div class="container container_bottom">
		<div class="row row_margin">
			<div class="col-md-12">
			<?php
			$getPageType = $_GET ['pageType'];
			$getId = $_GET ['id'];
			
			if ($getPageType == 1) {
				if ($login == null || $login->getGrade () > 2) {
					echo "<script type='text/javascript'>";
					echo "location.replace('./main.php');";
					echo "</script>";
					exit ();
				}
			}
			
			if ($getPageType != null) {
				switch ($getPageType) {
					case 1 : // 1:차량생성
						echo "<h2>차량 생성</h2>";
						break;
					case 2 : // 2:차량조회
					default :
						echo "<h2>차량 상세</h2>";
						break;
				}
			}
			if ($getPageType != 1) {
				$vehicle = new Vehicle ();
				$vehicle->search4Detail ( $getId );
			}
			?>
			</div>
		</div>
		<?php
		if ($getPageType != null) {
			switch ($getPageType) {
				case 1 : // 1:차량생성
					echo "<form method='post' action='./ajax/create_vehicle_data.php'>";
					break;
				case 2 : // 2:차량조회
					echo "<form method='post' action='./ajax/modify_vehicle_data.php'>";
					break;
			}
		}
		?>
		<div class="row row_margin">
			<div class="col-md-12">
				<div class="input-group row_margin">
					<span class="input-group-addon">차량식별 번호</span>
					<?php
					echo "<input type='text' id='car_id' name='car_id' class='form-control' placeholder='자동으로 생성됩니다.' readonly='readonly'";
					switch ($getPageType) {
						case 1 : // 1:차량생성
							echo ">";
							break;
						case 2 : // 2:차량조회
							echo " value='" . $vehicle->car_id . "' >";
							break;
					}
					?>
				</div>
				<div class="input-group row_margin">
					<span class="input-group-addon">차량등록 번호판</span> 
					
					<?php
					echo "<input required type='text' id='car_no' name='car_no' class='form-control' placeholder='ex> 서울01가1234'";
					echo " maxlength='10'";
					echo " onkeyup='javascript:checkHanNum(this)'";
					switch ($getPageType) {
						case 1 : // 1:차량생성
							echo ">";
							break;
						case 2 : // 2:차량조회
							echo " value='" . $vehicle->car_no . "' >";
							break;
					}
					?>
				</div>
				<div class="input-group row_margin">
					<span class="input-group-addon">차대 번호</span>
					<?php
					echo "<input required type='text' id='product_id' name='product_id' class='form-control' placeholder='ex> KMHSC81VP1U135410'";
					echo " maxlength='24'";
					echo " onkeyup='javascript:checkEnNum(this)'";
					switch ($getPageType) {
						case 1 : // 1:차량생성
							echo ">";
							break;
						case 2 : // 2:차량조회
							if ($login->getGrade () != 1) {
								echo " readonly='readonly'";
							}
							echo " value='" . $vehicle->product_id . "' >";
							break;
					}
					?>
				</div>
				<div class="input-group row_margin">
					<span class="input-group-addon">차량소속</span> 
					<?php
					echo "<select name='car_sosok' class='form-control'>";
					// switch ($getPageType) {
					// case 1 : // 1:차량생성
					// echo ">";
					// break;
					// case 2 : // 2:차량조회
					// echo " disabled='disabled'>";
					// break;
					// }
					// echo "!!!!! = " . $vehicle->car_sosok;
					$category = new Category ();
					$category->search4table ( '2', $vehicle->car_sosok );
					?>
						</select>
				</div>
<!-- 				<div class="input-group row_margin"> -->
<!-- 					<span class="input-group-addon">차량 소유</span>  -->
					<?php
// 					echo "<select id='soyu_tp' name='soyu_tp' class='form-control' onchange='javascript:changeDelemiter(this)'>";
// 					// switch ($getPageType) {
// 					// case 1 : // 1:차량생성
// 					// echo ">";
// 					// break;
// 					// case 2 : // 2:차량조회
// 					// echo " disabled='disabled'>";
// 					// break;
// 					// }
// 					$category = new Category ();
// 					$category->search4table ( '7', $vehicle->soyu_tp );
// 					?>
<!-- 						</select> -->
<!-- 				</div> -->
<!-- 				<div class="input-group row_margin"> -->
<!-- 					<span class="input-group-addon">거래처</span>  -->
					<?php
// 					echo "<select name='cusm_cd' class='form-control'>";
// 					// switch ($getPageType) {
// 					// case 1 : // 1:차량생성
// 					// echo ">";
// 					// break;
// 					// case 2 : // 2:차량조회
// 					// echo " disabled='disabled'>";
// 					// break;
// 					// }
// 					$category = new Category ();
// 					$category->search4table ( '4', $vehicle->cusm_cd );
// 					?>
<!-- 						</select> -->
<!-- 				</div> -->
<!-- 				<div class="input-group row_margin"> -->
<!-- 					<span class="input-group-addon">근무점포</span>  -->
					<?php
// 					echo "<select name='brno' class='form-control'>";
// 					// switch ($getPageType) {
// 					// case 1 : // 1:차량생성
// 					// echo ">";
// 					// break;
// 					// case 2 : // 2:차량조회
// 					// echo " disabled='disabled'>";
// 					// break;
// 					// }
// 					$category = new Category ();
// 					$category->search4table ( '3', $vehicle->brno );
// 					?>
<!-- 						</select> -->
<!-- 				</div> -->
				<div class="input-group row_margin">
					<span class="input-group-addon">번호판</span>
						<?php
						echo "<select name='license_plate' class='form-control'>";
						// switch ($getPageType) {
						// case 1 : // 1:차량생성
						// echo ">";
						// break;
						// case 2 : // 2:차량조회
						// echo " disabled='disabled'>";
						// break;
						// }
						
						if ($vehicle != null && ! empty ( $vehicle )) {
							switch ($vehicle->license_plate) {
								case 1 :
									echo "<option selected='selected' value='1'>영업</option>";
									echo "<option value='2'>업무</option>";
									break;
								case 2 :
									echo "<option value='1'>영업</option>";
									echo "<option selected='selected' value='2'>업무</option>";
									break;
							}
						} else {
							echo "<option selected='selected' value='1'>영업</option>";
							echo "<option value='2'>업무</option>";
						}
						?>
						</select>
				</div>
				<div class="input-group row_margin">
					<span class="input-group-addon">연식</span>
					<?php
					echo "<input type='text' id='made_in_y' name='made_in_y' class='form-control' placeholder='년'";
					echo " maxlength='4'";
					echo " onkeyup='javascript:checkNumber(this, false)'";
					switch ($getPageType) {
						case 1 : // 1:차량생성
							echo ">";
							break;
						case 2 : // 2:차량조회
							echo " value='" . $vehicle->made_in_y . "' >";
							break;
					}
					?>
						<span class="input-group-addon add-last">년</span> 
						<?php
						echo "<input type='text' id='made_in_m' name='made_in_m' class='form-control' placeholder='월'";
						echo " maxlength='2'";
						echo " onkeyup='javascript:checkNumber(this, false)'";
						switch ($getPageType) {
							case 1 : // 1:차량생성
								echo ">";
								break;
							case 2 : // 2:차량조회
								echo " value='" . $vehicle->made_in_m . "' >";
								break;
						}
						?>
						<span class="input-group-addon add-last">월</span>
				</div>
				<div class="input-group row_margin">
					<span class="input-group-addon">탑 형식</span>
						<?php
						echo "<select name='loop_tp' class='form-control'>";
						// switch ($getPageType) {
						// case 1 : // 1:차량생성
						// echo ">";
						// break;
						// case 2 : // 2:차량조회
						// echo " disabled='disabled'>";
						// break;
						// }
						
						if ($vehicle != null && ! empty ( $vehicle )) {
							switch ($vehicle->loop_tp) {
									case 0 :
									echo "<option selected='selected' value='0'>없음</option>";
									echo "<option value='1'>H</option>";
									echo "<option value='2'>L</option>";
									break;
								case 1 :
									echo "<option value='0'>없음</option>";
									echo "<option selected='selected' value='1'>H</option>";
									echo "<option value='2'>L</option>";
									break;
								case 2 :
									echo "<option value='0'>없음</option>";
									echo "<option value='1'>H</option>";
									echo "<option selected='selected' value='2'>L</option>";
									break;
							}
						} else {
							echo "<option selected='selected' value='0'>없음</option>";
							echo "<option value='1'>H</option>";
							echo "<option value='2'>L</option>";
						}
						?>
						</select>
				</div>
<!-- 				<div class="input-group row_margin"> -->
<!-- 					<span class="input-group-addon">관리비</span> -->
					<?php
// 					echo "<input required type='text' id='mng_amt' name='mng_amt' class='form-control' placeholder='ex> 100000'";
// 					echo " maxlength='20'";
// 					echo " onkeyup='javascript:checkNumber(this, true)'";
// 					switch ($getPageType) {
// 						case 1 : // 1:차량생성
// 							echo ">";
// 							break;
// 						case 2 : // 2:차량조회
// 							echo " value='" . $vehicle->mng_amt . "' >";
// 							break;
// 					}
// 					?>
<!-- 					<span class="input-group-addon add-last">원</span> -->
<!-- 				</div> -->
<!-- 				<div class="input-group row_margin" id='org_amt_div'> -->
<!-- 					<span class="input-group-addon">환경개선/협회비</span> -->
					<?php
// 					echo "<input required type='text' id='org_amt' name='org_amt' class='form-control' placeholder='ex> 15000'";
// 					echo " maxlength='20'";
// 					echo " onkeyup='javascript:checkNumber(this, true)'";
// 					switch ($getPageType) {
// 						case 1 : // 1:차량생성
// 							echo ">";
// 							break;
// 						case 2 : // 2:차량조회
// 							echo " value='" . $vehicle->org_amt . "' >";
// 							break;
// 					}
// 					?>
<!-- 					<span class="input-group-addon add-last">원</span> -->
<!-- 				</div> -->
<!-- 				<div class="input-group row_margin" id='gps_amt_div'> -->
<!-- 					<span class="input-group-addon">GPS</span> -->
					<?php
// 					echo "<input required type='text' id='gps_amt' name='gps_amt' class='form-control' placeholder='ex> 10000'";
// 					echo " maxlength='20'";
// 					echo " onkeyup='javascript:checkNumber(this, true)'";
// 					switch ($getPageType) {
// 						case 1 : // 1:차량생성
// 							echo ">";
// 							break;
// 						case 2 : // 2:차량조회
// 							echo " value='" . $vehicle->gps_amt . "' >";
// 							break;
// 					}
// 					?>
<!-- 					<span class="input-group-addon add-last">원</span> -->
<!-- 				</div> -->
<!-- 			</div> -->
				<div class="input-group row_margin">
					<span class="input-group-addon">현재기사</span> 
					<?php
					echo "<input required disabled type='text' id='cur_empl' name='cur_empl' class='form-control'";
					echo " maxlength='10'";
					switch ($getPageType) {
						case 1 : // 1:차량생성
							echo ">";
							break;
						case 2 : // 2:차량조회
							echo " value='" . $vehicle->cur_empl . "' >";
							break;
					}
					echo "<span class='input-group-addon input-group-addon-end add-last'>";
					echo "<button ";
					switch ($getPageType) {
						case 1 : // 1:차량생성
							echo "disabled ";
							break;
					}
					echo "class='btn btn-default btn-calendar'";
					echo ">조회하기</button></span>";
					?>
				</div>
			<!-- <div class="col-md-6">
				<div class="row row_margin">
					<div class="table-responsive">
						<table class="table table-bordered" style="overflow: scroll;">
							<thead>
								<tr>
									<th colspan="10">차량내역</th>
								</tr>
								<tr>
									<th>날짜</th>
									<th>내용</th>
									<th>금액</th>
									<th>비고</th>
								</tr>
							</thead>
							<tbody>
								<tr>
									<td>2014/1/1</td>
									<td>엔진오일 교체</td>
									<td>54000</td>
									<td>-</td>
								</tr>
								<tr>
									<td>2014/1/8</td>
									<td>홍길동 기사로 교체</td>
									<td>-</td>
									<td></td>
								</tr>
							</tbody>
						</table>
					</div>
				</div>
			</div> -->
		</div>
		<div class="row row_margin">
			<div class="col-md-12 text-right">
			<?php
			switch ($getPageType) {
				case 1 : // 1:차량생성
					echo "<button class='btn btn-lg btn-default' type='button'
						onclick='javascript:initData()'>입력 초기화</button>";
					break;
			}
			?>
				<button class="btn btn-lg btn-success" type="submit">저장</button>
				<button class="btn btn-lg btn-danger" type="button"
					onclick="window.history.back();">취소</button>
			</div>
		</div>
		</form>
	</div>
	<!-- /container -->

	<!-- Bootstrap core JavaScript
    ================================================== -->
	<!-- Placed at the end of the document so the pages load faster -->
	<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
	<script src="./dist/js/bootstrap.min.js"></script>
	<script type="text/javascript">
	$(document).ready(function () {
		$('#car_no').tooltip({'trigger':'focus', 'title': '최대 10자 이내 한글 또는 숫자를 조합하여 입력하세요.'});
		$('#product_id').tooltip({'trigger':'focus', 'title': '최대 24자 이내 영문 또는 숫자를 조합하여 입력하세요.'});
		$('#made_in_y').tooltip({'trigger':'focus', 'title': '최대 4자 이내 숫자만 입력하세요.'});
		$('#made_in_m').tooltip({'trigger':'focus', 'title': '최대 2자 이내 숫자만 입력하세요.'});
		$('#mng_amt').tooltip({'trigger':'focus', 'title': '최대 20자 이내 숫자만 입력하세요.'});
		$('#org_amt').tooltip({'trigger':'focus', 'title': '최대 20자 이내 숫자만 입력하세요.'});
		$('#gps_amt').tooltip({'trigger':'focus', 'title': '최대 20자 이내 숫자만 입력하세요.'});
	});

	function checkHanNum(obj)
	{
		for( var i=0; i < obj.value.length;i++)
		{
			var c = obj.value.charCodeAt(i);
			if( !( ( 0xAC00 <= c && c <= 0xD7A3 ) || ( 0x3131 <= c && c <= 0x318E ) ) && (obj.value.charAt(i) < '0' || obj.value.charAt(i) > '9')) {
				obj.value = obj.value.substr(0,i);
			}
		}
	}

	function checkEnNum(obj)
	{
		for( var i=0; i < obj.value.length;i++)
		{
			var c = obj.value.charCodeAt(i);
			if( !( (  65 <= c && c <= 90 ) || ( 97 <= c && c <= 122 ) ) && (obj.value.charAt(i) < '0' || obj.value.charAt(i) > '9')) {
				obj.value = obj.value.substr(0,i);
			}
		}
	}

	function checkNumber(obj, isWon)
	{
		if (obj.value.length > 0)
		{
			for (var i = 0; i < obj.value.length; i++)
			{
				if (!(isWon && obj.value.charAt(i) == ',') && (obj.value.charAt(i) < '0' || obj.value.charAt(i) > '9')) {
					obj.value = obj.value.substr(0,i);
				}
			}
			if (isWon) {
				obj.value = commaNum(obj.value);
			}
		}
	}

	function commaNum(num) {
		num = num.replace(/,/gi,'');
		var len, point, str;
		num = num + "";
		point = num.length % 3;
		len = num.length;

		str = num.substring(0, point);
		while (point < len) {
			if (str != "") str += ",";
			str += num.substring(point, point + 3);
			point += 3;
		}
		return str;
	}

	function changeDelemiter(obj) {
		if (obj.value == "4") {
			document.getElementById("org_amt").required = false;
			document.getElementById("gps_amt").required = false;
			document.getElementById("org_amt_div").style.display = "none";
			document.getElementById("gps_amt_div").style.display = "none";
		} else if (obj.value == "3"){
			document.getElementById("org_amt").required = true;
			document.getElementById("gps_amt").required = true;
			document.getElementById("org_amt_div").style.display = "table";
			document.getElementById("gps_amt_div").style.display = "table";
		}
	}
	function initData() {
		document.getElementById("car_no").value = "";
		document.getElementById("product_id").value = "";
		document.getElementById("made_in_y").value = "";
		document.getElementById("made_in_m").value = "";
		document.getElementById("mng_amt").value = "";
		document.getElementById("org_amt").value = "";
		document.getElementById("gps_amt").value = "";
	}
	$(window).load(function () {
		changeDelemiter(document.getElementById("soyu_tp"));
		checkNumber(document.getElementById("org_amt"), true);
		checkNumber(document.getElementById("mng_amt"), true);
		checkNumber(document.getElementById("gps_amt"), true);
	});
	</script>
</body>
</html>